
var num = 0;


//生成从minNum到maxNum的随机数
function randomNum(minNum,maxNum){
    switch(arguments.length){
        case 1:
            return parseInt(Math.random()*minNum+1,10);
            break;
        case 2:
            return parseInt(Math.random()*(maxNum-minNum+1)+minNum,10);
            break;
        default:
            return 0;
            break;
    }
}


/*破蛋*/
function activeEgg(){

    var num2 = randomNum(1,2);

    if(num < 1){
        var name = $(this).attr("name");//取到自己的name属性
        name = "."+name;

        $(name).show();//GIF显示
        $(this).hide();//隐藏自己
        num++;

        setTimeout(function(){
            if(num2 === 1){
                $('.black,.coupons').show();//显示优惠券
            }else if(num2 === 2){
                $('.black,.tpisbeer').show();//显示啤酒
            }else{
                alert("系统出错！");
            }
        },1500);

    }else{
        alert("只有一次机会哦！")
    }

}


$('.egg').click(activeEgg);


/*使用优惠券*/
function useTicket(){
    alert("在天猫店结算的时候自动使用");
}
$('#useTicket').click(useTicket);

/*关闭优惠券*/
function closeTicket(){
    $('.black,.coupons').hide();//隐藏优惠券
}
$('#closeTicket').click(closeTicket);




/*领取啤酒*/
function getBeer(){
    $(".tpisbeer").hide();//啤酒弹窗隐藏
    $('.address').show();//领取展示
}

$('#getBeer').click(getBeer);



/*提交表单*/
function submitForm(){
    var uname = $('#uname').val();
    var mobile = $('#mobile').val();
    var sAddress = $('#sAddress').val();

    if(uname === "" || mobile === "" || sAddress === ""){
        alert("请完整填写后再提交");
    }else{
        $('.address').hide();//隐藏提交表单
        $('.succeed').show();//展示成功
    }
}

//关闭表单
function closeForm(){
    $('.black,.address').hide();
};

$('.submitForm').click(submitForm);
$('#closeForm').click(closeForm);


//关闭提交成功
function successClos(){
    $('.black,.succeed').hide();
}
$('#successClose').click(successClos);





